package com.bckj.fastboot.iot.biz.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bckj.fastboot.iot.common.dto.query.IotAlarmRuleQuery;
import com.bckj.fastboot.iot.common.dto.response.IotAlarmRuleResponse;
import com.bckj.fastboot.iot.common.entity.IotAlarmRule;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;

import java.util.List;

/**
 * IotAlarmRuleMapper
 *
 * @author wfc
 * @date 2025/9/28 09:55
 **/
@Mapper
public interface IotAlarmRuleMapper extends BaseMapper<IotAlarmRule> {

    @Select("""
    select * from iot_alarm_rule
    where id=#{0}
    """)
    IotAlarmRuleResponse findById(Long id);

    @SelectProvider(type = IotAlarmRuleProvider.class, method = "findList")
    List<IotAlarmRuleResponse> findList(IotAlarmRuleQuery query);

    class IotAlarmRuleProvider {

        public String findList(IotAlarmRuleQuery query) {
            SQL sql = new SQL();
            sql.SELECT("ar.*");
            sql.FROM("iot_alarm_rule ar");
            listWhere(sql, query);
            return sql.toString();
        }

        private void listWhere(SQL sql, IotAlarmRuleQuery query) {

        }
    }
}
